home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: nntp.coast.net!torn!sis!apollo!gerrity
- From: gerrity@apollo.sheridanc.on.ca (Jason Gerrity)
- Subject: Is there a better way?
- Message-ID: <Dp6xn8.BvA@relay.sheridanc.on.ca>
- Sender: news@relay.sheridanc.on.ca (USENET News System)
- Nntp-Posting-Host: apollo.sheridanc.on.ca
- Organization: Sheridan College, Ont., Canada
- X-Newsreader: TIN [version 1.2 PL2]
- Date: Mon, 1 Apr 1996 15:57:08 GMT
-
- Hello All,
-
- I'm working on a piece of code that is giving me a headache,
- could some kind person point out a better or correct way of doing
- this?
-
- I'm parsing an input line using strtok and have spaces as the
- delimeter. I then need to check to see if certain 'words' have
- been inputed and then grab everything after the 'word' and use
- whats grabbed as a variable.
-
- Problem is that when using strtok, I use a while loop so as
- long as the strtok is not NULL then the loop continues, unfortunatley
- the strtok gets set to NULL on the first pass..here's my code so far:
-
-
-
- #include <stdio.h>
- #include <string.h>
-
- main()
- {
-
-
-
-
- int Counter;
- int Failure;
- int GenericAccount;
- int GenericAccountErase;
- int LinkOption;
- int ServerOption;
- int SetUIDOption;
- int checksetuid;
- int checkLinkOptionPath;
- int checkServerOptionPath;
- int checknoerase;
- char *Login;
- char *pLogin
- char ServerOptionPath[60];
- char LinkOptionPath[20];
- char *LogTemp;
-
- memset(ServerOptionPath,0 ,60);
- memset(LinkOptionPath, 0, 20);
-
- for (Counter = 0; Counter < 3; Counter++)
- {
- printf("\r\nLogin: ");
-
- gets(Login);
- pLogin = strtok(Login, " ");
- while(pLogin)
- {
- char *ptr;
- strcpy(ptr, pLogin);
-
- LogTemp = strstr(ptr, "check1");
- if (LogTemp)
- {
- checksetuid =1;
- SetUIDOption = 1;
- printf("\r\n%s option recognized", LogTemp);
- }
- else
- {
- if (checksetuid !=1)
- SetUIDOption = 0;
- }
-
- LogTemp = strstr(ptr, "check2");
- if (LogTemp)
- {
- checknoerase = 1;
- GenericAccountErase = 0;
- printf("\r\n%s option recognized", LogTemp);
- }
- else
- {
- if (checknoerase !=1)
- GenericAccountErase = 1;
- }
- LogTemp = strstr(ptr, "check3=");
- if (LogTemp)
- {
- char *NewTemp;
- memset(NewTemp,0 ,20);
- NewTemp = strstr(LogTemp, "=");
- strcpy(LinkOptionPath, &NewTemp[1]);
- checkLinkOptionPath =1;
- SetUIDOption = 1;
- LinkOption = 1;
- printf("\r\n%s option recognized", LogTemp);
- }
- else
- {
- if (checkLinkOptionPath !=1)
- LinkOption = 0;
- }
-
- LogTemp = strstr(ptr, "check4=");
- if (LogTemp)
- {
- char *TempNew2 = strstr(LogTemp, "=");
- strcpy(ServerOptionPath, &TempNew2[1]);
- checkServerOptionPath =1;
- SetUIDOption = 1;
- ServerOption = 1;
- printf("\r\n%s option recognized", LogTemp);
- }
- else
- {
- if (checkServerOptionPath !=1)
- ServerOption = 0;
- }
-
-
- printf("\r\nsetuid=%d",SetUIDOption);
- printf("\r\nnoerase=%d",GenericAccountErase);
- printf("\r\nLinkPathOption=%s",LinkOptionPath);
- printf("\r\nServerPathOption=%s",ServerOptionPath);
-
-
-
-
-
- }
-
- return 0;
- }
-
-
-
- I forgot to mention that I'm using borland's turbo c++ 3.0
- and this program seems to work only when using 'trace into'
-
- If I compile and run the program..it doesn't function properly.
- I think the while(pLogin) statement gets set to NULL too soon.
-
- Any help would be greatly appreciated...
-
- please e-mail jason.gerrity@sheridanc.on.ca
-
- thanks
-